package dk.nordahl.whereami;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.text.format.DateFormat;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);


		
		updateLocation();
	}
	public void updateLocation()
	{		
		LocationManager locMan;
		String service = Context.LOCATION_SERVICE;
		locMan = (LocationManager)getSystemService(service);
	
		String provider = LocationManager.GPS_PROVIDER;
		Location loc = locMan.getLastKnownLocation(provider);
		TextView locTextView = (TextView)findViewById(R.id.locationOut);
		
		String locString = "Location unknown";
		
		if(loc != null)
		{
			double lat = loc.getLatitude();
			double lon = loc.getLongitude();
			locString = "Lat: " + lat + "\nlong: " + lon;
		}
		
		locTextView.setText(locString);
	}
	public void clickUpdate(View view)
	{
		updateLocation();
		//TextView txt = (TextView)findViewById(R.id.textView1);
		Button btn = (Button)findViewById(R.id.button1);
		
		
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm" , Locale.UK);
		String updated = sdf.format(date);
		btn.setText("Updated \n" + updated );
		//txt.setText(sdf.format(date));
		
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
